package com.wnhz.work.yz.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.wnhz.work.yz.R;
import com.wnhz.work.yz.listener.OnItemClickListener;
import com.yanzhenjie.recyclerview.swipe.SwipeMenuAdapter;

import java.util.List;

/**
 * Created by admin on 2017/6/9.
 */
public class YanShouDai2Adapter extends SwipeMenuAdapter<YanShouDai2Adapter.DefaultViewHolder> {


    private OnItemClickListener mOnItemClickListener;
    private Context context;
    List<String> test;

    public YanShouDai2Adapter(List<String> test, Context context) {
        this.context = context;
        this.test = test;
    }

    public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
        this.mOnItemClickListener = onItemClickListener;
    }


    @Override
    public void onBindViewHolder(YanShouDai2Adapter.DefaultViewHolder holder, int position) {
        holder.setOnItemClickListener(mOnItemClickListener);
    }

    @Override
    public int getItemCount() {
        return test == null ? 0 : test.size();
    }

    @Override
    public View onCreateContentView(ViewGroup parent, int viewType) {
        return LayoutInflater.from(parent.getContext()).inflate(R.layout.item_yanshou_dai2, parent, false);
    }

    @Override
    public YanShouDai2Adapter.DefaultViewHolder onCompatCreateViewHolder(View realContentView, int viewType) {
        return new DefaultViewHolder(realContentView);
    }


    class DefaultViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        OnItemClickListener mOnItemClickListener;

        public DefaultViewHolder(View itemView) {
            super(itemView);
            itemView.setOnClickListener(this);

        }

        public void setOnItemClickListener(OnItemClickListener onItemClickListener) {
            this.mOnItemClickListener = onItemClickListener;
        }


        @Override
        public void onClick(View v) {
            if (mOnItemClickListener != null) {
                mOnItemClickListener.onItemClick(getAdapterPosition());
            }
        }


    }


}

